<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.2"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>kalman-cpp: kalman/ekf2.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript/MathJax.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">kalman-cpp
   </div>
   <div id="projectbrief">Implementation of Kalman Filter in C++</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.2 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',false,false,'search.php','Search');
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('ekf2_8h_source.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">ekf2.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="ekf2_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160; </div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="preprocessor">#ifndef EKF2_H</span></div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="preprocessor">#define EKF2_H</span></div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160; </div>
<div class="line"><a name="l00024"></a><span class="lineno"><a class="line" href="ekf2_8h.html#a525335710b53cb064ca56b936120431e">   24</a></span>&#160;<span class="preprocessor">#define _USE_MATH_DEFINES</span></div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;<span class="preprocessor">#include &lt;math.h&gt;</span></div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160; </div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;<span class="preprocessor">#include &lt;assert.h&gt;</span></div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;<span class="preprocessor">#include &lt;armadillo&gt;</span></div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160; </div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;<span class="keyword">using namespace </span>std;</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;<span class="keyword">using namespace </span>arma;</div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160; </div>
<div class="line"><a name="l00037"></a><span class="lineno"><a class="line" href="class_e_k_f2.html">   37</a></span>&#160;<span class="keyword">class </span><a class="code" href="class_e_k_f2.html">EKF2</a> {</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;<span class="keyword">public</span>:</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;    <a class="code" href="class_e_k_f2.html#a73120213612e130a1b8657a1b9c157b8">EKF2</a>();</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160; </div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;    <a class="code" href="class_e_k_f2.html#a1410c08c0b6eb0db519a3b94a0b3fb81">~EKF2</a>();</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160; </div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;    <span class="keywordtype">void</span> <a class="code" href="class_e_k_f2.html#ad67663f816588df77c3580ee22ab10e8">InitSystem</a>(<span class="keywordtype">int</span> n_states, <span class="keywordtype">int</span> n_outputs, <span class="keyword">const</span> mat&amp; Q, <span class="keyword">const</span> mat&amp; R);</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;    <span class="keyword">virtual</span> colvec <a class="code" href="class_e_k_f2.html#af895b6e04cce02a8144190f719167f29">f</a>(<span class="keyword">const</span> colvec &amp;x, <span class="keyword">const</span> colvec &amp;u);</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160; </div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;    <span class="keyword">virtual</span> colvec <a class="code" href="class_e_k_f2.html#a85bf920e64108a76ac586a0163d6e768">h</a>(<span class="keyword">const</span> colvec &amp;x);</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160; </div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;    <span class="keywordtype">void</span> <a class="code" href="class_e_k_f2.html#a3e4768d55e211a99bc28b6cd7f1ffb93">InitSystemState</a>(<span class="keyword">const</span> colvec&amp; x0);</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160; </div>
<div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;    <span class="keywordtype">void</span> <a class="code" href="class_e_k_f2.html#a67dffee5f528e1d3aebdcfb874ec39e7">InitSystemStateCovariance</a>(<span class="keyword">const</span> mat&amp; P0);</div>
<div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160; </div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;    <span class="keywordtype">void</span> <a class="code" href="class_e_k_f2.html#a4c257671712db2ed50a9bac1b201ebe1">EKalmanf</a>(<span class="keyword">const</span> colvec&amp; u);</div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160; </div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;    <span class="keywordtype">void</span> <a class="code" href="class_e_k_f2.html#a4c257671712db2ed50a9bac1b201ebe1">EKalmanf</a>(<span class="keyword">const</span> colvec&amp; z, <span class="keyword">const</span> colvec&amp; u);</div>
<div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160; </div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;    colvec* <a class="code" href="class_e_k_f2.html#af180026c5b458924417b9414f8c5957e">GetCurrentState</a>();</div>
<div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160; </div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;    colvec* <a class="code" href="class_e_k_f2.html#a42f2a80683305870c849bb363a4d713b">GetCurrentOutput</a>();</div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160; </div>
<div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;    colvec* <a class="code" href="class_e_k_f2.html#aca6143226980e2cb480b44e549dc79c6">GetCurrentEstimatedState</a>();</div>
<div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160; </div>
<div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;    colvec* <a class="code" href="class_e_k_f2.html#aa7f75a7bc89e1e652a464b0c68a123af">GetCurrentEstimatedOutput</a>();</div>
<div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160; </div>
<div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;<span class="keyword">private</span>:</div>
<div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;    mat CalcFx(<span class="keyword">const</span> colvec &amp;x, <span class="keyword">const</span> colvec &amp;u);</div>
<div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160; </div>
<div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;    mat CalcHx(<span class="keyword">const</span> colvec &amp;x);</div>
<div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160; </div>
<div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;    mat CalcFxx(<span class="keyword">const</span> colvec &amp;x, <span class="keyword">const</span> colvec &amp;u, <span class="keyword">const</span> <span class="keywordtype">int</span> i);</div>
<div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160; </div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;    mat CalcHxx(<span class="keyword">const</span> colvec &amp;x, <span class="keyword">const</span> <span class="keywordtype">int</span> i);</div>
<div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;    </div>
<div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;    colvec e(<span class="keyword">const</span> <span class="keywordtype">int</span> i, <span class="keyword">const</span> <span class="keywordtype">int</span> max_len);</div>
<div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160; </div>
<div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160;    mat Q_;          </div>
<div class="line"><a name="l00172"></a><span class="lineno">  172</span>&#160;    mat R_;          </div>
<div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160;    colvec v_;       </div>
<div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160;    colvec w_;       </div>
<div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160; </div>
<div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;    mat sqrt_Q_;     </div>
<div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;    mat sqrt_R_;     </div>
<div class="line"><a name="l00178"></a><span class="lineno">  178</span>&#160; </div>
<div class="line"><a name="l00179"></a><span class="lineno">  179</span>&#160;    colvec x_m_;     </div>
<div class="line"><a name="l00180"></a><span class="lineno">  180</span>&#160;    colvec x_p_;     </div>
<div class="line"><a name="l00181"></a><span class="lineno">  181</span>&#160; </div>
<div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;    mat P_p_;        </div>
<div class="line"><a name="l00183"></a><span class="lineno">  183</span>&#160;    mat P_m_;        </div>
<div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160; </div>
<div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160;    colvec z_m_; </div>
<div class="line"><a name="l00186"></a><span class="lineno">  186</span>&#160; </div>
<div class="line"><a name="l00187"></a><span class="lineno">  187</span>&#160;    <span class="keywordtype">double</span> epsilon_; </div>
<div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160; </div>
<div class="line"><a name="l00189"></a><span class="lineno">  189</span>&#160;<span class="keyword">protected</span>:</div>
<div class="line"><a name="l00190"></a><span class="lineno">  190</span>&#160; </div>
<div class="line"><a name="l00191"></a><span class="lineno"><a class="line" href="class_e_k_f2.html#a1f3f61b02a3213f4078b7b68b9d28741">  191</a></span>&#160;    <span class="keywordtype">int</span> <a class="code" href="class_e_k_f2.html#a1f3f61b02a3213f4078b7b68b9d28741">nStates_</a>;   </div>
<div class="line"><a name="l00192"></a><span class="lineno"><a class="line" href="class_e_k_f2.html#ada5ba3c1e9e8dcbfbefeeaad082207a0">  192</a></span>&#160;    <span class="keywordtype">int</span> <a class="code" href="class_e_k_f2.html#ada5ba3c1e9e8dcbfbefeeaad082207a0">nOutputs_</a>;  </div>
<div class="line"><a name="l00193"></a><span class="lineno">  193</span>&#160; </div>
<div class="line"><a name="l00194"></a><span class="lineno"><a class="line" href="class_e_k_f2.html#a25cae89d90ad4e89261a6a28c00cbe9c">  194</a></span>&#160;    colvec <a class="code" href="class_e_k_f2.html#a25cae89d90ad4e89261a6a28c00cbe9c">x_</a>;      </div>
<div class="line"><a name="l00195"></a><span class="lineno"><a class="line" href="class_e_k_f2.html#ad52e0e3cceeb94e83296503a3e1e9716">  195</a></span>&#160;    colvec <a class="code" href="class_e_k_f2.html#ad52e0e3cceeb94e83296503a3e1e9716">z_</a>;      </div>
<div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;};</div>
<div class="line"><a name="l00197"></a><span class="lineno">  197</span>&#160; </div>
<div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160; </div>
<div class="line"><a name="l00199"></a><span class="lineno">  199</span>&#160;<span class="preprocessor">#endif</span></div>
<div class="ttc" id="aclass_e_k_f2_html"><div class="ttname"><a href="class_e_k_f2.html">EKF2</a></div><div class="ttdoc">Implemetation of the extended Kalman filter. This class needs to be derived.</div><div class="ttdef"><b>Definition:</b> ekf2.h:37</div></div>
<div class="ttc" id="aclass_e_k_f2_html_a1410c08c0b6eb0db519a3b94a0b3fb81"><div class="ttname"><a href="class_e_k_f2.html#a1410c08c0b6eb0db519a3b94a0b3fb81">EKF2::~EKF2</a></div><div class="ttdeci">~EKF2()</div><div class="ttdoc">Destructur, nothing happens here.</div><div class="ttdef"><b>Definition:</b> ekf2.cpp:15</div></div>
<div class="ttc" id="aclass_e_k_f2_html_a1f3f61b02a3213f4078b7b68b9d28741"><div class="ttname"><a href="class_e_k_f2.html#a1f3f61b02a3213f4078b7b68b9d28741">EKF2::nStates_</a></div><div class="ttdeci">int nStates_</div><div class="ttdoc">Number of the states.</div><div class="ttdef"><b>Definition:</b> ekf2.h:191</div></div>
<div class="ttc" id="aclass_e_k_f2_html_a25cae89d90ad4e89261a6a28c00cbe9c"><div class="ttname"><a href="class_e_k_f2.html#a25cae89d90ad4e89261a6a28c00cbe9c">EKF2::x_</a></div><div class="ttdeci">colvec x_</div><div class="ttdoc">State vector.</div><div class="ttdef"><b>Definition:</b> ekf2.h:194</div></div>
<div class="ttc" id="aclass_e_k_f2_html_a3e4768d55e211a99bc28b6cd7f1ffb93"><div class="ttname"><a href="class_e_k_f2.html#a3e4768d55e211a99bc28b6cd7f1ffb93">EKF2::InitSystemState</a></div><div class="ttdeci">void InitSystemState(const colvec &amp;x0)</div><div class="ttdoc">Initialize the system states. Must be called after InitSystem. If not called, system state is initial...</div><div class="ttdef"><b>Definition:</b> ekf2.cpp:169</div></div>
<div class="ttc" id="aclass_e_k_f2_html_a42f2a80683305870c849bb363a4d713b"><div class="ttname"><a href="class_e_k_f2.html#a42f2a80683305870c849bb363a4d713b">EKF2::GetCurrentOutput</a></div><div class="ttdeci">colvec * GetCurrentOutput()</div><div class="ttdoc">Get current simulated true output. This is analogous to the measurements.</div><div class="ttdef"><b>Definition:</b> ekf2.cpp:268</div></div>
<div class="ttc" id="aclass_e_k_f2_html_a4c257671712db2ed50a9bac1b201ebe1"><div class="ttname"><a href="class_e_k_f2.html#a4c257671712db2ed50a9bac1b201ebe1">EKF2::EKalmanf</a></div><div class="ttdeci">void EKalmanf(const colvec &amp;u)</div><div class="ttdoc">Do the extended Kalman iteration step-by-step while simulating the system. Simulating the system is d...</div><div class="ttdef"><b>Definition:</b> ekf2.cpp:182</div></div>
<div class="ttc" id="aclass_e_k_f2_html_a67dffee5f528e1d3aebdcfb874ec39e7"><div class="ttname"><a href="class_e_k_f2.html#a67dffee5f528e1d3aebdcfb874ec39e7">EKF2::InitSystemStateCovariance</a></div><div class="ttdeci">void InitSystemStateCovariance(const mat &amp;P0)</div><div class="ttdoc">Initialize the system state covariance. Must be called after InitSystem. If not called,...</div><div class="ttdef"><b>Definition:</b> ekf2.cpp:176</div></div>
<div class="ttc" id="aclass_e_k_f2_html_a73120213612e130a1b8657a1b9c157b8"><div class="ttname"><a href="class_e_k_f2.html#a73120213612e130a1b8657a1b9c157b8">EKF2::EKF2</a></div><div class="ttdeci">EKF2()</div><div class="ttdoc">Constructor, nothing happens here.</div><div class="ttdef"><b>Definition:</b> ekf2.cpp:10</div></div>
<div class="ttc" id="aclass_e_k_f2_html_a85bf920e64108a76ac586a0163d6e768"><div class="ttname"><a href="class_e_k_f2.html#a85bf920e64108a76ac586a0163d6e768">EKF2::h</a></div><div class="ttdeci">virtual colvec h(const colvec &amp;x)</div><div class="ttdoc">Define the output model of your system.</div><div class="ttdef"><b>Definition:</b> ekf2.cpp:65</div></div>
<div class="ttc" id="aclass_e_k_f2_html_aa7f75a7bc89e1e652a464b0c68a123af"><div class="ttname"><a href="class_e_k_f2.html#aa7f75a7bc89e1e652a464b0c68a123af">EKF2::GetCurrentEstimatedOutput</a></div><div class="ttdeci">colvec * GetCurrentEstimatedOutput()</div><div class="ttdoc">Get current estimated output.</div><div class="ttdef"><b>Definition:</b> ekf2.cpp:279</div></div>
<div class="ttc" id="aclass_e_k_f2_html_aca6143226980e2cb480b44e549dc79c6"><div class="ttname"><a href="class_e_k_f2.html#aca6143226980e2cb480b44e549dc79c6">EKF2::GetCurrentEstimatedState</a></div><div class="ttdeci">colvec * GetCurrentEstimatedState()</div><div class="ttdoc">Get current estimated state. This is analogous to the filtered measurements.</div><div class="ttdef"><b>Definition:</b> ekf2.cpp:273</div></div>
<div class="ttc" id="aclass_e_k_f2_html_ad52e0e3cceeb94e83296503a3e1e9716"><div class="ttname"><a href="class_e_k_f2.html#ad52e0e3cceeb94e83296503a3e1e9716">EKF2::z_</a></div><div class="ttdeci">colvec z_</div><div class="ttdoc">Output matrix.</div><div class="ttdef"><b>Definition:</b> ekf2.h:195</div></div>
<div class="ttc" id="aclass_e_k_f2_html_ad67663f816588df77c3580ee22ab10e8"><div class="ttname"><a href="class_e_k_f2.html#ad67663f816588df77c3580ee22ab10e8">EKF2::InitSystem</a></div><div class="ttdeci">void InitSystem(int n_states, int n_outputs, const mat &amp;Q, const mat &amp;R)</div><div class="ttdoc">Tell me how many states and outputs you have!</div><div class="ttdef"><b>Definition:</b> ekf2.cpp:20</div></div>
<div class="ttc" id="aclass_e_k_f2_html_ada5ba3c1e9e8dcbfbefeeaad082207a0"><div class="ttname"><a href="class_e_k_f2.html#ada5ba3c1e9e8dcbfbefeeaad082207a0">EKF2::nOutputs_</a></div><div class="ttdeci">int nOutputs_</div><div class="ttdoc">Number of outputs.</div><div class="ttdef"><b>Definition:</b> ekf2.h:192</div></div>
<div class="ttc" id="aclass_e_k_f2_html_af180026c5b458924417b9414f8c5957e"><div class="ttname"><a href="class_e_k_f2.html#af180026c5b458924417b9414f8c5957e">EKF2::GetCurrentState</a></div><div class="ttdeci">colvec * GetCurrentState()</div><div class="ttdoc">Get current simulated true state.</div><div class="ttdef"><b>Definition:</b> ekf2.cpp:263</div></div>
<div class="ttc" id="aclass_e_k_f2_html_af895b6e04cce02a8144190f719167f29"><div class="ttname"><a href="class_e_k_f2.html#af895b6e04cce02a8144190f719167f29">EKF2::f</a></div><div class="ttdeci">virtual colvec f(const colvec &amp;x, const colvec &amp;u)</div><div class="ttdoc">Define model of your system.</div><div class="ttdef"><b>Definition:</b> ekf2.cpp:58</div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_dc133b73f91f0e3b4287924ed00a2a00.html">kalman</a></li><li class="navelem"><a class="el" href="ekf2_8h.html">ekf2.h</a></li>
    <li class="footer">Generated on Thu Apr 1 2021 04:15:37 for kalman-cpp by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.2 </li>
  </ul>
</div>
</body>
</html>
